<?php
/**
 * 毛文科
 */
namespace short\bind;
use think\Db;
use think\Exception;

class LinKai
{
    protected $corpid = '';
    protected $pwd = '';
    protected $mobil = '';
    public function __construct($id=1,$table=null)
    {
        if(!$table){
            $table = request()->module().'_linkai';
        }
        $data = Db::name($table)
            ->where('id',$id)
            ->find();
        if($data){
            $this->corpid = $data['user'];
            $this->pwd = $data['pwd'];
        }else{
            throw new Exception('没有设置数据!!');
        }

    }
    public function setCorpId($user=null){
        if($user){
            $this->corpid = $user;
        }
        return $this;
    }
    public function setPwd($pwd=null){
        if($pwd){
            $this->pwd = $pwd;
        }
        return $this;
    }
    public function getCorpID(){
        if(isset($this->corpid)){
            return $this->corpid;
        }
        throw new \Exception('没有设置user');
    }
    public function getPwd(){
        if(isset($this->pwd)){
            return $this->pwd;
        }
        throw new \Exception('没有设置pwd');
    }
    public function setMobile(string $mobil=''){
        if($mobil){
            $this->mobile = $mobil;
        }
    }
    public function getMobile(){
        if(isset($this->mobile)){
            return $this->mobile;
        }
        throw new \Exception('请设置手机');
    }
    public function senMoBan($Mobile='',$Content="尊敬的用户，你有试卷需要审核，请及时处理!"){
        if($Mobile){
            $this->setMobile($Mobile);
        }
        header("Content-type: text/html; charset=utf-8");
        date_default_timezone_set('PRC');
        $url = "https://sdk2.028lk.com/sdk2/BatchSend2.aspx?";
        $ContentS = rawurlencode(mb_convert_encoding($Content, "gb2312", "utf-8"));
        $curpost = "CorpID=".$this->getCorpID()."&Pwd=".$this->getPwd()."&Mobile=".$this->getMobile()."&Content=".$ContentS."&Cell=&SendTime=";
        $data = file_get_contents($url.$curpost);
        return $data;
    }
}
